<?php
class Contenido extends AppModel {
	var $name = 'Contenido';
		
	function generateCodigo(){
		$result = $this->query('select 
									COALESCE(cast(max(d.codigo) as integer)+1,1) as "Contenido__codigo" 
								from portal.Contenidos d 
								where d.activo = true');
		$result = $result[0];
		return str_repeat('0',4-strlen($result['Contenido']['codigo'])).$result['Contenido']['codigo'];			
	}	
}
?>